package control.panel
{
	import global.GameState;
	
	import model.sit.ISitData;
	
	import utils.OpenWindow;
	
	import view.panel.AddFriendPanel;
	import view.panel.play.SelfInfoPanel;
	
	public class AddFriendPanelControl extends PanelControl
	{
		public function AddFriendPanelControl()
		{
			initPanel();
		}
		
		private function initPanel():void
		{
			_view.addFriendPanel = new AddFriendPanel(this);
			_view.selfInfoPanel = new SelfInfoPanel(this);
		}
		
		public function open(sitId:int) : void
		{
			_control.itemPanelControl.currentSitId = sitId.toString();
			var sitData:ISitData = _model.sitModel.getSitDataById(sitId);
			
			if (sitData)
			{
				if (sitId == GameState.playerCurrentSitId)
				{
					_view.selfInfoPanel.update(sitData.roleData);
					_view.selfInfoPanel.open();	
					_view.addFriendPanel.close();
				}
				else
				{
					_view.addFriendPanel.update(sitData.roleData);
					_view.addFriendPanel.open();
					_view.selfInfoPanel.close();
				}
			}
		}
		
		public function goHomePage():void
		{
			var sitData:ISitData = _model.sitModel.getSitDataById(int(_control.itemPanelControl.currentSitId));
			if (sitData)
			{
				OpenWindow.openWindow(sitData.roleData.homePage);
			}
			_view.addFriendPanel.close();
			_view.selfInfoPanel.close();
		}
	
		
		public function onAddFriendApply(sitId:int):void
		{
			_model.netRemote.sendFriendApply(sitId.toString());
			_view.addFriendPanel.close();
		}
		
		public function itemUse(isSelf:Boolean = true):void
		{
			_control.itemPanelControl.open(isSelf);
			
			_view.addFriendPanel.close();
		}
		
		public function onPresent():void//赠送道具
		{
			_control.itemPanelControl.open(true,true);
			_view.addFriendPanel.close();
		}
		
		public function sendPresentMoney(v:int):void//赠送金钱
		{
			_model.netRemote.sendItem(_control.itemPanelControl.currentSitId,"0",v.toString());
			_view.addFriendPanel.close();
		}
		
	}
}